home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2002 #3
/
Amiga Plus CD - 2002 - No. 03.iso
/
AmiSoft
/
Mus
/
Play
/
Mhm_mayhem.lha
/
mhm-mAYhem_deli
/
hardAY
/
hardAY.s
< prev
next >
Wrap
Text File
|
2002-08-15
|
6KB
|
456 lines
;DEBUG set 1
;READ_OK set 1
XDEF _hardAY_On
XDEF _hardAY_Off
XDEF _hardAY_Shut
XDEF _hardAY_WrRegList
XDEF _hardAY_RdRegList
XDEF _hardAY_SetFreq
include exec/exec_lib.i2
include resources/misc.i
include resources/misc_lib.i
IFD DEBUG
bsr hardAY_On
bsr hardAY_Shut
move.l #1750000,d0
bsr hardAY_SetFreq
bsr hardAY_Off
rts
buffer dc.w $0000,$0100,$0200,$0300,$0400,$0500,$0600,$07FF
dc.w $0800,$0900,$0A00,$0B00,$0C00,$0D00,$0E00,$0F00
ENDC
DATA_PORT equ $BFE101
DATA_DIR equ $BFE301
AUX_PORT equ $BFD000
AUX_DIR equ $BFD200
INPUTS MACRO
clr.b DATA_DIR
ENDM
OUTPUTS MACRO
st.b DATA_DIR
ENDM
WR_REG MACRO
move.b \1,DATA_PORT ;set AY register
or.b #$05,AUX_PORT
and.b #$FA,AUX_PORT
move.b \2,DATA_PORT ;write into AY register
or.b #$01,AUX_PORT
and.b #$FE,AUX_PORT
ENDM
RD_REG MACRO
move.b \1,DATA_PORT ;set AY register
or.b #$05,AUX_PORT
and.b #$FA,AUX_PORT
INPUTS
or.b #$04,AUX_PORT
move.b DATA_PORT,\2 ;read from AY register
and.b #$FB,AUX_PORT
OUTPUTS
ENDM
hardAY_On:
_hardAY_On:
;grab parallel port, check AY presence
;result in d0.l: 0 - success
; +2 - can't grab all port-related stuff
; +1 - no AY
;in case of success, hardAY_Off must be called to free all stuff
;otherwise, everything opened will be closed back before returning
movem.l d1-d7/a0-a6,-(sp)
move.w #2,Success
move.l 4.w,a6
lea MiscResName(pc),a1
jsr _LVOOpenResource(a6)
move.l d0,MiscBase
beq.s .nores
move.l d0,a6
moveq #MR_PARALLELPORT,d0
lea OwnerString(pc),a1
jsr _LVOAllocMiscResource(a6)
tst.l d0
bne.s .nopport
moveq #MR_PARALLELBITS,d0
lea OwnerString(pc),a1
jsr _LVOAllocMiscResource(a6)
tst.l d0
bne.s .nopbits
subq.w #1,Success
and.b #$FA,AUX_PORT ;init port hardware
or.b #$05,AUX_DIR
OUTPUTS
moveq #7,d0
moveq #$78,d1
bsr.s .wrreg
clr.b d1
bsr.s .wrreg
bsr.s .wrreg
bsr.s .wrreg
moveq #14,d0
moveq #(16+6),d1
bsr.s .wrreg
IFD READ_OK
moveq #7,d0
bsr.s .rdreg
;;;;;;;;;;; cmp.b #127,d1
;;;;;;;;;;; bne.s .noAY
addq.b #1,d1
bvc.s .noAY
clr.b d2
bsr.s .rdreg
bsr.s .rdreg
bsr.s .rdreg
;;;;;;;;;;; and.b #$1F,d2
lsl.b #3,d2
bne.s .noAY
moveq #14,d0
bsr.s .rdreg
cmp.b #(16+6),d1
bne.s .noAY
ENDC
subq.w #1,Success
.nores
.nopport
.return
moveq #0,d0
move.w Success(pc),d0
movem.l (sp)+,d1-d7/a0-a6
rts
.noAY
move.l MiscBase(pc),a6
moveq #MR_PARALLELBITS,d0
jsr _LVOFreeMiscResource(a6)
.nopbits
moveq #MR_PARALLELPORT,d0
jsr _LVOFreeMiscResource(a6)
bra.s .return
.wrreg
WR_REG d0,d1
addq.b #1,d0
rts
.rdreg
RD_REG d0,d1
addq.b #1,d0
or.b d1,d2
rts
hardAY_Off:
_hardAY_Off:
;release all allocations & shut AY
;safe to call even if hardAY_ON failed
tst.w Success
bne.s .return
movem.l d0-d7/a0-a6,-(sp)
bsr.s hardAY_Shut
move.l MiscBase(pc),a6
moveq #MR_PARALLELBITS,d0
jsr _LVOFreeMiscResource(a6)
moveq #MR_PARALLELPORT,d0
jsr _LVOFreeMiscResource(a6)
movem.l (sp)+,d0-d7/a0-a6
.return
rts
hardAY_Shut:
_hardAY_Shut:
;clear up all AY regs ($07 will be set to $FF)
movem.l d0/a0,-(sp)
lea ClearSeq(pc),a0
moveq #16,d0
bsr.s hardAY_WrRegList
movem.l (sp)+,d0/a0
return3
rts
hardAY_WrRegList:
_hardAY_WrRegList:
;write reglist to AY
;a0 - ptr to reglist
;d0.b - number of regs to out
;reglist: (regnumber).b,(regvalue).b, ...
tst.w Success
bne.s return3
movem.l d0-d2/a0,-(sp)
cmp.b #16,d0
bls.s .numok
moveq #16,d0
.numok
.loop
move.b (a0)+,d1
move.b (a0)+,d2
cmp.b #7,d1
bne.s .no7
move.b d2,AYreg7
and.b #$3F,d2
and.b #$C0,AYreg7
or.b #$40,d2
bra.s .wrreg
.no7
cmp.b #14,d1
blo.s .less14
cmp.b #15,d1
bhi.s .endloop
beq.s .wr15
move.b d2,AYreg14
bra.s .endloop
.wr15
move.b d2,AYreg15
bra.s .endloop
.less14
.wrreg
WR_REG d1,d2
.endloop
subq.b #1,d0
bne.s .loop
movem.l (sp)+,d0-d2/a0
return2
rts
hardAY_RdRegList:
_hardAY_RdRegList:
;will read reg content of AY
;args same as in hardAY_WrRegList, but (regvalue).b will be filled with new data
tst.w Success
bne.s return2
movem.l d0-d2/a0,-(sp)
cmp.b #16,d0
bls.s .numok
moveq #16,d0
.numok
.loop
move.b (a0)+,d1
cmp.b #14,d1
blo.s .less14
cmp.b #15,d1
bhi.s .endloop
beq.s .rd15
move.b AYreg14(pc),d2
bra.s .2mem
.rd15
move.b AYreg15(pc),d2
bra.s .2mem
.less14
RD_REG d1,d2
cmp.b #7,d1
bne.s .no7
and.b #$3F,d2
or.b AYreg7(pc),d2
.no7
.2mem
move.b d2,(a0)
.endloop
addq.l #1,a0
subq.b #1,d0
bne .loop
movem.l (sp)+,d0-d2/a0
return1
rts
hardAY_SetFreq:
_hardAY_SetFreq:
;sets frequency of AY
;d0.l - freq (in Hz) - may be 1-2MHz, other will be truncated
tst.w Success
bne.s return1
movem.l d0-d6/a0,-(sp)
cmp.l #1000000,d0
bhs.s .moreeq1M
move.l #1000000,d0
.moreeq1M
cmp.l #2000000,d0
bls.s .lesseq2M
move.l #2000000,d0
.lesseq2M
lea FreqTable(pc),a0
moveq #-1,d1
.selloop
move.l (a0)+,d2
beq.s .endloop
bpl.s .checkfit
move.l d2,d3
neg.l d3
bra.s .selloop
.checkfit
move.l d2,d4
sub.l d0,d4
bpl.s .noneg
neg.l d4
.noneg
cmp.l d1,d4
bhs.s .selloop
move.l d4,d1
move.l d2,d5
move.l d3,d6
bra.s .selloop
.endloop
move.l d6,d4
moveq #-3,d0
.calcrem
addq.b #1,d0
sub.l d5,d4
bcc.s .calcrem
and.b #$0F,d0
cmp.l #14000000,d6
bne.s .no14M
or.b #$10,d0
.no14M
WR_REG #14,d0
movem.l (sp)+,d0-d6/a0
rts
cnop 0,4
FreqTable dc.l -14000000,2000000 ;check freqs in descending order
dc.l -8867238,1773447
dc.l -14000000,1750000,1555555
dc.l -8867238,1477873
dc.l -14000000,1400000,1272727
dc.l -8867238,1266748
dc.l -14000000,1166666
dc.l -8867238,1108404
dc.l -14000000,1076923,1000000
dc.l 0
MiscBase dc.l 0
Success dc.w 0
ClearSeq dc.w $0000,$0100,$0200,$0300,$0400,$0500,$0600,$07FF
dc.w $0800,$0900,$0A00,$0B00,$0C00,$0D00,$0E00,$0F00
AYreg7 dc.b 0
AYreg14 dc.b 0
AYreg15 dc.b 0
MiscResName dc.b 'misc.resource',0
OwnerString dc.b 'hardAY interface of mAYhem package',0